package com.atguigui.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 283.移动零
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/6/7 9:50
 */
public class P283MoveZeroes {
    public static void main(String[] args) {
        Solution solution = new P283MoveZeroes().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public void moveZeroes(int[] nums) {
            int n = 0;
            List<Integer> list = new ArrayList<Integer>();

            for (int i = 0; i < nums.length; i++) {
                if (nums[i] != 0) {
                    list.add(nums[i]);
                } else {
                    n++;
                }
            }

            for (int i = 0; i < list.size(); i++) {
                nums[i] = list.get(i);
            }

            for (int i = list.size(); i < n + list.size(); i++) {
                nums[i] = 0;
            }


        }
    }
}
